package fucai.com.fucai.DialogCreater;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;

import fucai.com.fucai.R;

/**
 * Control dialog in whole project
 *
 * @author nicky.han
 */
@SuppressLint("ValidFragment")
public class DialogCreater extends DialogFragment
{
    public static final int DIALOG_EXIT = 10001;
    public static final int DIALOG_PROGRESS = 10002;
    /**
     * Get activity res
     */
    private Context mContext = null;
      @Override
    public void dismiss()
    {
        super.dismiss();
    }

    @Override
    public Dialog getDialog()
    {
        return super.getDialog();
    }

    @Override
    public void show(FragmentManager manager, String tag)
    {
        super.show(manager, tag);
    }

    /**
     * Show dialog by dialog id
     *
     * @param manager
     * @param id
     */
    public void showDialog(FragmentManager manager, int id)
    {
        try
        {
            Bundle args = new Bundle();
            args.putInt(mContext.getResources().getString(R.string.dialog_fragment_key), id);
            this.setArguments(args);
            this.show(manager, mContext.getResources().getString(R.string.dialog_fragment_tag));
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    private Dialog createProgressDialog()
    {
        OnKeyListener onKeyListener = new OnKeyListener()
        {
            @Override
            public boolean onKey(DialogInterface arg0, int arg1, KeyEvent arg2)
            {
                return true;
            }
        };
        LayoutInflater mInflater = LayoutInflater.from(mContext);
        View convertView = mInflater.inflate(R.layout.progress_dialog_view, null);
        Dialog dialog = new Dialog(mContext, R.style.CustomProgressDialog);
        dialog.setContentView(convertView);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setOnKeyListener(onKeyListener);
        return dialog;
    }

}
